<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>轮播</title>
  <!-- https://www.swiper.com.cn/ -->
  <style>
    .swiper-container {
      position: relative;
      height: 500px;
      perspective: 1200px;
      overflow: hidden;
    }
    .swiper-container .swiper-pre {
      position: absolute;
      top: 50%;
      left: 100px;
      z-index: 10;
    }
    .swiper-container .swiper-next {
      position: absolute;
      top: 50%;
      right: 100px;
      z-index: 10;
    }
    .swiper-pane {
      width: 600px;
      height: 400px;
      background: gray;
      flex-shrink: 0;
    }
    .swiper-pane > h1 {
      line-height:400px;
      text-align: center;
    }
    .active {
      color: red;
    }
  </style>
</head>
<body> 
  <div id="app">
    <div class="swiper-container">
      <button @click="pre" class="swiper-pre">上一个</button>
      <div style="display: flex;" :style="getWaper()">
        <div v-for="i in 6" :key="i" class="swiper-pane" :class="{'active': i === active}" :style="getStyle(i)">
          <h1>{{i}}</h1>
        </div>
      </div>
      <button @click="next" class="swiper-next">下一个</button>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    var app = new Vue({
      el: '#app',
      data: {
        active: 1
      },
      methods: {
        pre() {
          this.active -= 1
          this.active <= 0 ? this.active = 6 : null
        },
        next() {
          this.active += 1
          this.active > 6 ? this.active = 1 : null
        },
        getWaper(i) {
          const width = 6 * 600;
          const x = (this.active - 1) * 600
          return {
            transitionDuration: '200ms',
            width: `${width}px`,
            transform: `translate3d(${-x}px, 0px, 0px)`,
            zIndex: '1',
          }
        },
        getStyle(i) {
          return {}
          // let x = 0
          // let z = 0
          // if (i === this.active) {
          //   x = 0;
          //   z = 0;
          // } else {
          //   z = -400
          //   x = (this.active - i) * 600
          // }
          // return {
          //   transitionDuration: '0ms',
          //   transform: `translate3d(${x}px, 0px, ${z}px)`,
          //   zIndex: '1',
          // }
        }
      }
    })
  </script>
</body>
</html>